import axios from "axios";
import { API_NAME } from "./contants.ts";
import { RequestDiscussion, RequestReply } from "../index";

const getAllDiscussionAPI = () => {
  return axios.get(`${API_NAME}/discussion/all`);
};

const getDiscussionByIDAPI = (id: number) => {
  return axios.get(`${API_NAME}/discussion/${id}`);
};

const addDiscussionAPI = (discussion: RequestDiscussion) => {
  return axios.post(`${API_NAME}/discussion/publish`, {
    ...discussion,
  });
};

const getLatestReplyAPI = () => {
  return axios.get(`${API_NAME}/reply/latest`);
};

const addReplyAPI = (reply: RequestReply) => {
  return axios.post(`${API_NAME}/reply/add`, {
    ...reply,
  });
};

export {
  getAllDiscussionAPI,
  getDiscussionByIDAPI,
  addDiscussionAPI,
  addReplyAPI,
  getLatestReplyAPI,
};
